home *** CD-ROM | disk | FTP | other *** search
/ PC Open 103 / PC Open 103 CD 1.bin / CD1 / INTERNET / EMAIL / pop file / setup.exe / popfile.pl < prev    next >
Encoding:
Perl Script  |  2004-11-30  |  4.0 KB  |  123 lines

  1. #!/usr/bin/perl
  2. # ----------------------------------------------------------------------------
  3. #
  4. # popfile.pl --- Message analyzer and sorter
  5. #
  6. # Acts as a server and client designed to sit between a real mail/news
  7. # client and a real mail/ news server using POP3.  Inserts an extra
  8. # header X-Text-Classification: into the header to tell the client
  9. # which category the message belongs in and much more...
  10. #
  11. # Copyright (c) 2001-2004 John Graham-Cumming
  12. #
  13. #   This file is part of POPFile
  14. #
  15. #   POPFile is free software; you can redistribute it and/or modify
  16. #   it under the terms of the GNU General Public License as published by
  17. #   the Free Software Foundation; either version 2 of the License, or
  18. #   (at your option) any later version.
  19. #
  20. #   POPFile is distributed in the hope that it will be useful,
  21. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. #   GNU General Public License for more details.
  24. #
  25. #   You should have received a copy of the GNU General Public License
  26. #   along with POPFile; if not, write to the Free Software
  27. #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. #
  29. #   Modified by     Sam Schinke (sschinke@users.sourceforge.net)
  30. #
  31. # ----------------------------------------------------------------------------
  32.  
  33. # Check the packing list of POPFile to ensure that all the required
  34. # modules are present.
  35.  
  36. my $packing_list = defined($ENV{POPFILE_ROOT})?$ENV{POPFILE_ROOT}:'./';
  37. $packing_list =~ s/[\\\/]$//;
  38. $packing_list .= '/popfile.pck';
  39.  
  40. my $fatal = 0;
  41. my $log = '';
  42.  
  43. if ( open PACKING, "<$packing_list" ) {
  44.     while (<PACKING>) {
  45.         if ( /^(REQUIRED|OPTIONAL-([^\t]+))\t([^\t]+)\t([^\r\n]+)/ ) {
  46.             my ( $required, $why, $version, $module ) = ( $1, $2, $3, $4 );
  47.  
  48.             # Find the module and set $ver to the loaded version, or -1 if
  49.             # the module was not found
  50.  
  51.             local $::SIG{__DIE__};
  52.             local $::SIG{__WARN__};
  53.             eval "require $module";
  54.             my $ver = ${"${module}::VERSION"} || ${"${module}::VERSION"} || 0;
  55.             $ver = ${"${module}::VERSION"} || ${"${module}::VERSION"} || 0;
  56.             $ver = -1 if $@;
  57.  
  58.             if ( $ver == -1 ) {
  59.                 if ( $required eq 'REQUIRED' ) {
  60.                     $fatal = 1;
  61.                     print STDERR "ERROR: POPFile needs Perl module $module, please install it.\n";
  62.                 } else {
  63.                     $log .= "WARNING: POPFile may require Perl module $module; it is needed for \"$why\".\n";
  64.                 }
  65.             }
  66.         }
  67.     }
  68.     close PACKING;
  69. } else {
  70.     $log .= "WARNING: Couldn't open POPFile packing list ($packing_list) so cannot check configuration\n";
  71. }
  72.  
  73. use strict;
  74. use locale;
  75. use lib defined($ENV{POPFILE_ROOT})?$ENV{POPFILE_ROOT}:'./';
  76. use POPFile::Loader;
  77.  
  78. # POPFile is actually loaded by the POPFile::Loader object which does all
  79. # the work
  80.  
  81. my $POPFile = POPFile::Loader->new();
  82.  
  83. # Indicate that we should create output on STDOUT (the POPFile
  84. # load sequence) and initialize with the version
  85.  
  86. $POPFile->debug(1);
  87. $POPFile->CORE_loader_init();
  88.  
  89. # Redefine POPFile's signals
  90.  
  91. $POPFile->CORE_signals();
  92.  
  93. # Create the main objects that form the core of POPFile.  Consists of
  94. # the configuration modules, the classifier, the UI (currently HTML
  95. # based), platform specific code, and the POP3 proxy.  The link the
  96. # components together, intialize them all, load the configuration from
  97. # disk, start the modules running
  98.  
  99. $POPFile->CORE_load();
  100. $POPFile->CORE_link_components();
  101. $POPFile->CORE_initialize();
  102. if ( $POPFile->CORE_config() ) {
  103.     $POPFile->CORE_start();
  104.  
  105.     # If there were any log messages from the packing list check then
  106.     # log them now
  107.  
  108.     if ( $log ne '' ) {
  109.         $POPFile->get_module( 'POPFile::Logger' )->debug( 0, $log );
  110.     }
  111.  
  112.     # This is the main POPFile loop that services requests, it will
  113.     # exit only when we need to exit
  114.  
  115.     $POPFile->CORE_service();
  116.  
  117.     # Shutdown every POPFile module
  118.  
  119.     $POPFile->CORE_stop();
  120. }
  121.  
  122. # END
  123.